package com.huitone.gddw.service.impl.analysis.traffic;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huitone.gddw.dao.analysis.traffic.IUpFlowRepDao;
import com.huitone.gddw.dao.entity.RecvSm;
import com.huitone.gddw.dao.entity.SmFlow;
import com.huitone.gddw.model.support.QueryPage;
import com.huitone.gddw.service.analysis.traffic.IUpFlowRepService;
import com.huitone.gddw.service.dto.analysis.traffic.UpFlowRepDTO;
import com.huitone.gddw.service.dto.analysis.traffic.UpSmRecDTO;
import com.huitone.gddw.service.system.IRoleService;
import com.huitone.gddw.utils.StringUtils;
import com.huitone.gddw.utils.SysLoginUtil;

/**
 *上行短信流量分析 接口实现类
 * @author chengsiyyue
 *
 */
@Service
public class UpFlowRepService implements IUpFlowRepService {

	@Autowired
	private IUpFlowRepDao upFlowRepDao;
	
	@Autowired
	private IRoleService roleService;

	@Override
	public QueryPage<UpFlowRepDTO> selectPage(QueryPage<SmFlow> page) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("isUnit",roleService.isRootAcsFlag(SysLoginUtil.getLoginUserId())?"1":"0");
		map.put("isSvrNode", page.getParams().get("isSvrNode"));
		map.put("isGateLink", page.getParams().get("isGateLink"));
		map.put("svrNode",page.getParams().get("svrNode"));
		map.put("gateLinkId", page.getParams().get("gateLinkId"));
		map.put("startDate", page.getParams().get("startDate"));
		map.put("endDate", page.getParams().get("endDate"));
		map.put("userId", SysLoginUtil.getLoginUserId());
		

		List<UpFlowRepDTO> result = upFlowRepDao.selectPage(map);
		
		QueryPage<UpFlowRepDTO> queryPage = new QueryPage<UpFlowRepDTO>();
		queryPage.setResult(result);
		return queryPage;
	}

	@Override
	public List<UpFlowRepDTO> getRecord(Map<String, Object> map) {
		map.put("isUnit",roleService.isRootAcsFlag(SysLoginUtil.getLoginUserId())?"1":"0");
		map.put("userId", SysLoginUtil.getLoginUserId());
		return upFlowRepDao.getRecord(map);
	}

	@Override
	public QueryPage<UpSmRecDTO> selectDetial(QueryPage<RecvSm> page) {
		Map<String, Object> map = page.getParams();
		map.put("isUnit",roleService.isRootAcsFlag(SysLoginUtil.getLoginUserId())?"1":"0");
		map.put("userId", SysLoginUtil.getLoginUserId());
		map.put("start", (page.getPageNo() - 1) * page.getPageSize()+1);
		map.put("end", (page.getPageNo() - 1) * page.getPageSize() + page.getPageSize());

		List<UpSmRecDTO> result = upFlowRepDao.selectDetial(map);
		
		int totalCount = upFlowRepDao.selectCount(map);
		QueryPage<UpSmRecDTO> queryPage = new QueryPage<UpSmRecDTO>();
		queryPage.setResult(result);
		queryPage.setPageNo(page.getPageNo());
		queryPage.setPageSize(page.getPageSize());
		queryPage.setTotalCount(totalCount);
		return queryPage;
	}

	@Override
	public List<UpSmRecDTO> getRecordDetial(Map<String, Object> map) {
		map.put("isUnit",roleService.isRootAcsFlag(SysLoginUtil.getLoginUserId())?"1":"0");
		map.put("userId", SysLoginUtil.getLoginUserId());
		return upFlowRepDao.getRecordDetial(map);
	}
}
